package com.pixeljet.html5.client;

import com.google.gwt.core.client.JavaScriptObject;

public class XHR2 {

	public static void post(String url, JavaScriptObject data) {
		post(url, data, null);
	}
	
	public static void post(String url, JavaScriptObject data, XHRCallback callback) {
		nativePost(url, data, callback);
	}
	
	public static native void nativePost(String url, JavaScriptObject data, XHRCallback callback) /*-{
		var xhr = new XMLHttpRequest();
		xhr.open("POST", url);
		xhr.onreadystatechange = function() {
			if (this.readyState == 4 && this.status == 200) {  
            	callback.@com.pixeljet.html5.client.XHRCallback::onSuccess(Ljava/lang/String;)(this.responseText);
        	}  
		};
		xhr.send(data);
	}-*/;
}
